// Script for spawning enemies in various formations chosen randomly
// at the time of execution of the code.
// Enemy to be spawning is passed in as argument0

var randFormation = choose(0,1,2,3);
var centerFormation = random(100) + 200;
var heightFormation = -60;
var xShift = 45;
var yShift = 20;
var rows = choose(2,3);
var i = 1;

instance_create (centerFormation, heightFormation, argument0);

// randFormation = 0 calls for enemies to be spawned in V formation.
if (randFormation == 0)
{    
    do
    {
        instance_create (centerFormation + ( xShift * i ), heightFormation - ( yShift * i ), argument0);
        instance_create (centerFormation - ( xShift * i ), heightFormation - ( yShift * i ), argument0);
        i++;
    } until ( i >= rows );
}

// randFormation = 1 or 2  calls for enemies to be spawned in diagonal formation
if (randFormation == 1)
{
    do
    {
        instance_create ( centerFormation + ( xShift * i ), heightFormation + ( yShift * i ), argument0);
        instance_create ( centerFormation - ( xShift * i ), heightFormation - ( yShift * i ), argument0);
        i++;
    } until ( i >= rows );
}

if (randFormation == 2)
{
    do
    {
        instance_create ( centerFormation + ( xShift * i ), heightFormation - ( yShift * i ), argument0);
        instance_create ( centerFormation - ( xShift * i ), heightFormation + ( yShift * i ), argument0);
        i++;
    } until ( i >= rows );
}

// randFormation = 3 calls for enemies to be spawned in a straight line
if (randFormation == 3)
{
    do
    {
        instance_create ( centerFormation + ( xShift * i ), heightFormation, argument0);
        instance_create ( centerFormation - ( xShift * i ), heightFormation, argument0);
        i++;
    } until ( i >= rows );
}

alarm[0] = 120+random(120);